/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * 
 * @author yaoyuming
 * 
 * @date 2019-12-04 16:28
 */
package com.yao.cloud.consumer.controller;

import cn.hutool.core.lang.Console;
import cn.hutool.core.util.IdUtil;
import com.yao.cloud.consumer.apiclient.EurekaApi;
import com.yao.cloud.consumer.entity.ServerEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 使用 Feign 请求
 * 
 * @author yaoyuming
 * @date 2019/12/04 16:28
 */
@RestController
@RequestMapping(value = "/feign")
public class FeignController {

    @Autowired
    private EurekaApi eurekaApi;

    @GetMapping(value = "/get")
    public String get1() {
        String serverInfo = eurekaApi.getServerInfo();
        Console.log(serverInfo);
        return serverInfo;
    }

    @GetMapping(value = "/post1")
    public ServerEntity post1() {
        String name = "yaoyuming";
        return eurekaApi.post1(name);
    }

    @GetMapping(value = "/post2")
    public ServerEntity post2() {
        return eurekaApi.post2(new ServerEntity().setIp(IdUtil.randomUUID()));
    }

    @GetMapping(value = "/getserver")
    public ServerEntity get2() {
        return eurekaApi.get("yaoyuming-" + IdUtil.randomUUID(), IdUtil.randomUUID());
    }

    @GetMapping(value = "/list")
    public List<String> list() {
        List<Integer> collect = Stream.of(1, 2, 3, 4, 5, 1000).collect(Collectors.toList());
        // throw new RuntimeException("list 接口异常");
        return eurekaApi.list(collect);
    }

}